package com.budwk.app.sqfw.controllers.admin.communityservice;

import cn.dev33.satoken.annotation.SaCheckLogin;
import com.budwk.app.sqfw.services.communityservice.SqfwShopInfoForAdminService;
import com.budwk.app.sqfw.vo.SqfwCustomForAdminCommonVO;
import com.budwk.app.sqfw.vo.SqfwShopInfoVO;
import com.budwk.app.sqfwV2.service.ShopsBaseInfoService;
import com.budwk.starter.common.openapi.annotation.*;
import com.budwk.starter.common.page.Pagination;
import com.budwk.starter.common.result.Result;
import com.budwk.starter.log.annotation.SLog;
import lombok.extern.slf4j.Slf4j;
import org.nutz.ioc.loader.annotation.Inject;
import org.nutz.ioc.loader.annotation.IocBean;
import org.nutz.mvc.annotation.*;
import org.nutz.mvc.upload.TempFile;
import org.nutz.mvc.upload.UploadAdaptor;

import java.util.List;

/**
 * @program: community-admin
 * @description: 商铺数据管理
 * @author: LJT
 * @create: 2024-07-02 10:45
 **/
@IocBean
@At("/platform/sqfw/shopInfo")
@ApiDefinition(tag = "商铺数据管理（后台管理系统）")
@Slf4j
public class SqfwShopInfoForAdminController {

    @Inject
    private ShopsBaseInfoService shopsBaseInfoService;

    @Inject
    private SqfwShopInfoForAdminService sqfwShopInfoForAdminService;

    @At
    @Ok("json")
    @POST
    @ApiOperation(name = "列表查询")
    @ApiFormParams(
            value = {
                    @ApiFormParam(name = "pageNo", example = "1", description = "页码", type = "integer"),
                    @ApiFormParam(name = "pageSize", example = "10", description = "页大小", type = "integer"),
                    @ApiFormParam(name = "pageOrderName", example = "create_date", description = "排序字段"),
                    @ApiFormParam(name = "pageOrderBy", example = "descending", description = "排序方式")
            },
            implementation = SqfwShopInfoVO.class
    )
    @ApiResponses(
            implementation = SqfwShopInfoVO.class
    )
    @SaCheckLogin
    public Result<?> page(@Param("..") SqfwShopInfoVO bean) {
        Pagination pagination = sqfwShopInfoForAdminService.page(bean);
        return Result.data(pagination);
    }

    @At
    @Ok("json")
    @POST
    @ApiOperation(name = "导入商铺数据")
    @SLog(tag = "导入商铺数据")
    @ApiFormParams(
            value = {
                    @ApiFormParam(name = "file", example = "1", description = "文件")
            }
    )
    @AdaptBy(type = UploadAdaptor.class)
    @SaCheckLogin
    public Result<?> uploadShopInfo(@Param("file") TempFile file, SqfwShopInfoVO bean) {
        return Result.data(sqfwShopInfoForAdminService.uploadShopInfo(file, bean));
    }

    @At
    @Ok("json")
    @POST
    @ApiOperation(name = "导出商铺数据")
    @SLog(tag = "导出商铺数据")
    @SaCheckLogin
    public Result<?> exportShopInfo(@Param("..") SqfwShopInfoVO bean) {
        return Result.data(sqfwShopInfoForAdminService.exportShopInfo(bean));
    }

    @At
    @Ok("json")
    @DELETE
    @ApiOperation(name = "批量删除表数据")
    @SLog(tag = "批量删除表数据", value = "${args[0]}")
    @SaCheckLogin
    public Result<?> batchDelete(@Param("ids") List<String> ids) {
        return Result.data(sqfwShopInfoForAdminService.batchDelete(ids));
    }

    @At("/getMainBusinessInfo")
    @Ok("json")
    @GET
    @ApiOperation(name = "获取主营业务枚举")
    @SaCheckLogin
    public Result<?> getMainBusinessInfo() {
        return Result.data(sqfwShopInfoForAdminService.getMainBusinessInfo());
    }

    @At("/detail/{flag}/{id}")
    @Ok("json")
    @GET
    @ApiOperation(name = "获取详情")
    @SaCheckLogin
    public Result<?> detail(String flag, String id) {
        return Result.data(sqfwShopInfoForAdminService.detail(flag, id));
    }

    @At("/pageByShopId")
    @Ok("json")
    @POST
    @ApiOperation(name = "商铺对应记录列表查询")
    @ApiFormParams(
            value = {
                    @ApiFormParam(name = "pageNo", example = "1", description = "页码", type = "integer"),
                    @ApiFormParam(name = "pageSize", example = "10", description = "页大小", type = "integer"),
                    @ApiFormParam(name = "pageOrderName", example = "create_date", description = "排序字段"),
                    @ApiFormParam(name = "pageOrderBy", example = "descending", description = "排序方式")
            },
            implementation = SqfwCustomForAdminCommonVO.class
    )
    @ApiResponses(
            implementation = SqfwCustomForAdminCommonVO.class
    )
    @SaCheckLogin
    public Result<?> pageByShopId(@Param("..") SqfwCustomForAdminCommonVO bean) {
        Pagination pagination = sqfwShopInfoForAdminService.pageByShopId(bean);
        return Result.data(pagination);
    }
}
